import java.util.*;

/**
 * 通过组合的方式将List对象的操作委托给底层的list实例来实现对list的操作，
 * 从而实现扩展，并且线程安全
 *
 * Collections.synchronizedList(new ArrayList());
 */
public class ImprovedList<E> implements List<E> {
    private final List<E> list;

    public ImprovedList(List<E> list) {
        this.list = list;
    }

    /**
     * 扩展 - 若没有则添加
     *
     * @param obj
     * @return boolean
     * @throws
     **/
    public synchronized boolean putIfAbsent(E obj) {
        boolean contains =  list.contains(obj);
        if (!contains) {
            list.add(obj);
        }
        return contains;
    }


    @Override
    public synchronized void clear() {
        list.clear();
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public boolean contains(Object o) {
        return false;
    }

    @Override
    public Iterator<E> iterator() {
        return null;
    }

    @Override
    public Object[] toArray() {
        return new Object[0];
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return null;
    }

    @Override
    public boolean add(E e) {
        return false;
    }

    @Override
    public boolean remove(Object o) {
        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        return false;
    }

    @Override
    public boolean addAll(int index, Collection<? extends E> c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public E get(int index) {
        return null;
    }

    @Override
    public E set(int index, E element) {
        return null;
    }

    @Override
    public void add(int index, E element) {

    }

    @Override
    public E remove(int index) {
        return null;
    }

    @Override
    public int indexOf(Object o) {
        return 0;
    }

    @Override
    public int lastIndexOf(Object o) {
        return 0;
    }

    @Override
    public ListIterator<E> listIterator() {
        return null;
    }

    @Override
    public ListIterator<E> listIterator(int index) {
        return null;
    }

    @Override
    public List<E> subList(int fromIndex, int toIndex) {
        return null;
    }

    public static void main(String[] args) {
        Collections.synchronizedList(new ArrayList());
        ImprovedList<String> list = new ImprovedList(new ArrayList());
        list.putIfAbsent("a");

    }
}
